package usersInfo

import (
	"gin/common/lib/gorm"
	"gin/dao/entity"
)

// Update 修改用户信息
func Update(uid int64, f map[string]interface{}) {
	gorm.GinDb.SubTable("cmf_users_info", uid).Where("uid = ?", uid).Updates(&f)
}

// Add 添加用户信息
func Add(f map[string]interface{}) {
	gorm.GinDb.SubTable("cmf_users_info", f["uid"]).Create(&f)
}

// Get 获取用户信息
func Get(uid int64) entity.UsersInfo {
	userInfo := entity.UsersInfo{}
	gorm.GinDb.SubTable("cmf_users_info", uid).Where("uid = ?", uid).Limit(1).Find(&userInfo)
	return userInfo
}

// DelToken 删除用户token
func DelToken(id int64) error {
	return gorm.GinDb.SubTable("cmf_users_info", id).Where("uid = ?", id).Updates(
		map[string]interface{}{
			"token":       "",
			"expire_time": -1,
		}).Error
}
